﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Data.Entity;
using UNFEventPosting.Models;

namespace UNFEventPosting
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Event", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            Database.SetInitializer<EventsDB>(new EventsDBInitializer());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }

    public class EventsDBInitializer : DropCreateDatabaseIfModelChanges<EventsDB>
    {
        protected override void Seed(EventsDB context)
        {
            base.Seed(context);

            //
            // Create and insert some categories
            var categories = new List<Category>
            {
                new Category { ID = 0, Name = "Clubs" },
                new Category { ID = 1, Name = "General" },
                new Category { ID = 2, Name = "Social" },
                new Category { ID = 3, Name = "Sporting" },
                new Category { ID = 4, Name = "UNF Hosted" }
            };

            categories.ForEach(s => context.Categories.Add(s));
            context.SaveChanges();

            //
            // Create and insert some events
            var events = new List<Event>
            {
                new Event { ID = Guid.NewGuid(), 
                    N_Number = "N00123456", 
                    CategoryID = 2, 
                    Name = "Blood Drive", 
                    Description = "Blood Drive on the Green!!! Free food and drinks for all donors.", 
                    Location = "UNF; The Green", 
                    Notes = "If you want to donate blood, but are unable to make it to this event check out or website to find another blood drive near you.",
                    StartTime = new DateTime(2012, 5, 9, 11, 0, 0), 
                    EndTime = new DateTime(2012, 5, 9, 16, 0, 0), 
                    Confirmed = true},

                new Event { ID = Guid.NewGuid(), 
                    N_Number = "N87654321", 
                    CategoryID = 1, 
                    Name = "ACM", 
                    Description = "ACM meeting for members to discuss the current state of the UNF's ACM website. Free food and website.", 
                    Location = "UNF; Matthew's Building", 
                    StartTime = new DateTime(2012, 5, 9, 11, 0, 0), 
                    EndTime = new DateTime(2012, 5, 11, 16, 0, 0), 
                    Confirmed = true},

                new Event { ID = Guid.NewGuid(), 
                    N_Number = "N87654321", 
                    CategoryID = 4, 
                    Name = "Baseball", 
                    Description = "UNF vs. Bethune - Cookman", 
                    Location = "UNF; Baseball Field", 
                    StartTime = new DateTime(2012, 5, 10, 18, 0, 0), 
                    EndTime = new DateTime(2012, 5, 10, 23, 0, 0),
                    Confirmed = false},

                new Event { ID = Guid.NewGuid(), 
                    N_Number = "N00651521", 
                    CategoryID = 4, 
                    Name = "Baseball", 
                    Description = "UNF vs. Florida A&M", 
                    Location = "At Florida A&M", 
                    StartTime = new DateTime(2012, 5, 11, 18, 0, 0), 
                    EndTime = new DateTime(2012, 5, 11, 23, 0, 0),
                    Confirmed = true}
            };

            events.ForEach(s => context.Events.Add(s));
            context.SaveChanges();
        }
    }
}